package pt;


/**
 * @author wcj
 * @Date 2021/7/6 22:44
 * @Version 1.0
 */
public class TwoSum {

    /**
     * 在一个有序数组中寻找值为target的两个数字的下标
     *
     * @param arr
     * @param target
     * @return
     */
    public static int[] pt(int[] arr, int target) {
        int low = 0;
        int high = arr.length - 1;
        while (low < high) {
            int sum = arr[low] + arr[high];
            if (sum > target) {
                high--;
            } else if (sum < target) {
                low++;
            } else {
                return new int[]{low, high};
            }
        }
        return new int[0];
    }
}
